package com.frank.demo.io.nio;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * Created by Administrator on 2018/10/13 0013.
 */
public class FileNio {
    /**
     * 文件channel不能非阻塞，所以不能使用selector
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        FileChannel fc = new FileInputStream(new File(FileNio.class.getClassLoader().getResource("demo.properties").getPath())).getChannel();
        ByteBuffer buf = ByteBuffer.allocate(100);
        while (fc.read(buf) != -1) {
            System.out.println(new String(buf.array()));
            buf.flip();
            System.out.println(buf);
        }

        fc.close();
    }
}
